<?php
session_start(); 
$choose_id=$_GET['choose_id'];
$type_id=$_GET['type_id'];
$set_change=$_SESSION['set_change'];
$teacher_id=$_SESSION['id'];
require_once('../include/connect.inc.php');
require_once('../include/layout-jquery.php');
	if($_SESSION['sess_id'] <> session_id()){
	?>
 	<SCRIPT LANGUAGE="JavaScript">
		alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
		location="login.php";
	</script>
<?php }?>
<?php 
echo $choice=$_POST[choice];
echo $q=$_POST[q_id];
for($i=0;$i<=20;$i++)
	{
		echo $choice[$i];
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="../template/template_style_wood.css">
</head>

<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a  href="../person_tea.php">ข้อมูลส่วนตัว</a>
		<a href="../tea_edit.php">เปลี่ยนรหัสผ่านใหม่</a>
        
        <a href="show_subject.php">จัดการรายวิชา</a>
		<a  href="../teacher_test.php">จัดการข้อสอบ</a>
        <a class="active" href="../teacher_tests.php">จัดการชุดข้อสอบ</a>
        <a  href="../agree_set.php">กำหนดสิทธิ์</a>
		<a href="../exam/tea_chack.php">ตรวจสอบคะแนน</a>
        <a href="../news/manage_news.php">ประกาศข่าวสาร</a>
        <a href="../problem/send_problem.php">แสดงความคิดเห็น</a>
        <a href="../logout.php">ออกจากระบบ</a>
		</div></div>       
<div id="p3">    
<div id="header"></div>
<div id="page"><div id="p1">คุณ<?php echo $_SESSION['teacher_name'];?><hr/>    
 <table  border="0" cellspacing="0" cellpadding="0">
     <tr>
        <th align="right"><a href="frm_manage_show_set.php?set_id=<?php echo $set_change;?>"><img src="../images/undo.png" border="0" /></a></th>
    </tr>
</table>
<form id="form1" name="form1" method="post" action="frm_manage_edit_set.php">
<?php 
if($type_id!=5){
$query2= query("SELECT * FROM  tb_question where question_id='$choose_id' ");
	while ($rs2= fetch_array($query2)) {
		$question_id=$rs2['question_id'];
		$question_detail=$rs2['question_detail'];
		$type_id=$rs2['type_id'];
		$topic_id=$rs2['topic_id'];
		$level_q_id=$rs2['level_q_id'];
?>
<input type="hidden" name="old_id" id="old_id"  value="<?php echo "$question_id";?>"/>
<table border="1"  id="table-t" width="40%">
	<tr>
		<td><div>"ข้อคำถาม" ที่ต้องการเปลี่ยนออก</br>คือ...!!!</br></br> " <?php echo $question_detail; ?> "</div>
<?php
$query3 = query("SELECT * FROM tb_choice  where question_id='".$rs2['question_id']."'order by choice_id ASC");
	while ($rs3 = fetch_array($query3)){
	?>
<div class="p21">
<?php  if($rs2['type_id']==4){?>
	<input type="text" name="answord[]" id="answord[]" />
<?php }
	if($rs2['type_id'] != 5){
	if($rs2['type_id'] != 7){
	if($rs2['type_id'] == 2){
?>
	<label>
    	<input type="checkbox" name="choice[]<?=$count?>"  value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
    </label>
<?php }else{ ?>
	<label>
		<input type="radio" name="choice[]<?=$count?>" value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
	</label>
<?php }?>
<?php  echo $rs3['choice_detail'];?>
	<?php }?>
		<?php }?>
	</div>
<?php }?>
	</tr>
</table>
</br>
<?php }?>

ข้อคำถามที่สามารถนำมาแทนได้ ...!!!
<?php 
$count=0;
$queryq= query("SELECT * FROM tb_set_detail where question_id!='0' AND set_id='".$_SESSION['set_change']."'");
	while ($rsq = fetch_array($queryq)) {
		  	$q_id=$rsq['question_id'];
		  	$count++;
			//echo print_r($q_id);
		//echo "</br>";
}
	/*for($i=0;$i<$count;$i++){
		echo $i;
		echo $q_id[$i];*/
	
$query50= query("SELECT * FROM  tb_question where type_id='$type_id' AND question_id!='$q_id' AND question_id!='$choose_id' AND topic_id='$topic_id' AND level_q_id='$level_q_id' ");
		while ($rs50= fetch_array($query50)){
			$question_id50=$rs50['question_id'];
		}
$query7= query("SELECT * FROM  tb_question where type_id=$type_id AND question_id!='$choose_id' AND topic_id='$topic_id' AND level_q_id='$level_q_id' ");
	if (num_rows($query7)<1){
	?>
	<SCRIPT LANGUAGE="JavaScript">
			alert("ไม่มีข้อที่สามารถเปลี่ยนแทนที่ได้...!");
			location="frm_manage_show_set.php?set_id=<?php echo "$set_change";?>";
			</script>
     <?
	}
	while ($rs7= fetch_array($query7)){
		$question_id7=$rs7['question_id'];
		$question_detail7=$rs7['question_detail'];
		$type_id7=$rs7['type_id'];
?>
<table border="1"  id="table-t" width="40%">
	<tr>
		<td>
        <input type="hidden" name="type_id" id="type_id" value="<?php echo "$type_id7";?>"/>
          <input type="radio" name="replace" id="replace" value="<?php echo "$question_id7";?>" />"กดปุ่ม"เพื่อเลือกข้อนี้แทนที่
          <div>" <?php echo "$question_detail7"; ?> "</div>
<?php
$query3 = query("SELECT * FROM tb_choice  where question_id='".$rs7['question_id']."'order by choice_id ASC");
	while ($rs3 = fetch_array($query3)){
	?>
<div class="p21">
<?php  if($rs7['type_id']==4){?>
	<input type="text" name="answord[]" id="answord[]" />
<?php }
	if($rs7['type_id'] != 5){
	if($rs7['type_id'] != 7){
	if($rs7['type_id'] == 2){
?>
	<label>
    	<input type="checkbox" name="choice[]<?=$count?>"  value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
    </label>
<?php }else{ ?>
	<label>
		<input type="radio" name="choice[]<?=$count?>" value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
	</label>
<?php }?>
<?php  echo $rs3['choice_detail'];?>
	<?php }?>
		<?php }?>
	</div>
<?php }?>	
	</tr>
</table>
<?php }?>
</br>

<?php }else{ //เงื่อนไข if else บนสุด?>
"ข้อสอบจับคู่" ชุดที่จะเปลี่ยนคือ ชุดที่ <?php echo "$choose_id";?>
<input type="hidden" name="old_id" id="old_id"  value="<?php echo "$choose_id";?>"/>
<table border="0" cellpadding="0" cellspacing="0"  id="table-m" >
	<tr>
      <td width="187"><font size="+1"><strong>คำถาม</strong></font></td>
      <td width="198"><font size="+1"><strong>คำตอบ</strong></font></td>
      <td width="198"><font size="+1"><strong>ข้อลวง</strong></font></td>
    </tr>
<?php 
$queryQ= query("SELECT * FROM tb_question where match_set='$choose_id' ");
		while ($rs = fetch_array($queryQ)) {
			$question_id=$rs['question_id'];
			$question_detail=$rs['question_detail'];
			$topic_id=$rs['topic_id'];
			$level_q_id=$rs['level_q_id'];
			$num++;
?>
    <tr>
		<td>ข้อที่<?php echo $num?>) <?php echo "$question_detail";?></td>
      	<td>
<?php 
	$queryC= query("SELECT * FROM tb_choice where match_set='$choose_id' and question_id=$question_id and answer!=0");
		while ($rs = fetch_array($queryC)) {
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
?>
			คำตอบข้อที่ <?php echo $num?>) <?php echo "$choice_detail";?>
<?php }?>
       </td>
       <td>
<?php }?>
<table border="0">
	<tr>
		<td>
<?php
$numlie=0;
	$querylie= query("SELECT * FROM tb_choice where match_set=$choose_id and answer=0");
		while ($rs = fetch_array($querylie)){
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
			$numlie++;
			?>
           ข้อลวงที่ <?php echo $numlie?>) <?php echo "$choice_detail";?>
		</td>
        <?php }?>
	</tr>
</table>
       </td>
    </tr>
</table>
</br></br>

ชุดที่เปลี่ยนได้!
<?php 
$query2= query("SELECT DISTINCT match_set FROM  tb_question where match_set!='$choose_id' AND topic_id='$topic_id' AND level_q_id='$level_q_id' ");
	if (num_rows($query2)<1){
	?>
<SCRIPT LANGUAGE="JavaScript">
	alert("ไม่มีชุดข้อสอบที่สามารถเปลี่ยนแทนที่ได้...!");
	location="frm_manage_show_set.php?set_id=<?php echo "$set_id";?>";
	</script>
<?php
	}
	while ($rs2= fetch_array($query2)){
		$match_set =$rs2['match_set'];
?>
ชุดที่ <?php echo "$match_set";?></br>
<input type="hidden" name="type_id" id="type_id" value="<?php echo "$type_id";?>"/>
<input type="radio" name="replace" id="replace" value="<?php echo "$match_set";?>" />"กดปุ่ม"เพื่อเลือกชุดนี้ไปแทนที่ชุดเดิม
<table border="0" cellpadding="0" cellspacing="0"  id="table-m" >
	<tr>
      <td width="187"><font size="+1"><strong>คำถาม</strong></font></td>
      <td width="198"><font size="+1"><strong>คำตอบ</strong></font></td>
      <td width="198"><font size="+1"><strong>ข้อลวง</strong></font></td>
    </tr>
<?php 
$queryQ= query("SELECT * FROM tb_question where match_set='$match_set' ");
		while ($rs = fetch_array($queryQ)) {
			$question_id=$rs['question_id'];
			$question_detail=$rs['question_detail'];
			$topic_id=$rs['topic_id'];
			$level_q_id=$rs['level_q_id'];
			$num++;
?>
    <tr>
		<td>ข้อที่<?php echo $num?>) <?php echo "$question_detail";?></td>
      	<td>
<?php 
	$queryC= query("SELECT * FROM tb_choice where match_set='$match_set' and question_id=$question_id and answer!=0");
		while ($rs = fetch_array($queryC)) {
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
?>
			คำตอบข้อที่ <?php echo $num?>) <?php echo "$choice_detail";?>
<?php }?>
       </td>
       <td>
<?php }?>
<table border="0">
	<tr>
		<td>
<?php
$numlie=0;
	$querylie= query("SELECT * FROM tb_choice where match_set='$match_set' and answer=0");
		while ($rs = fetch_array($querylie)){
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
			$numlie++;
			?>
           ข้อลวงที่ <?php echo $numlie?>) <?php echo "$choice_detail";?>
		</td>
        <?php }?>
	</tr>
</table>
       </td>
    </tr>
</table>
<?php }//ปิด while ชุดที่เปลี่ยนได้?>
<?php }//ปิดคำสั่ง else?>
<input type="submit" name="btn_replace" id="btn_replace" value="ตกลง" />
</form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>
